package com.neusoft.weekreport.component.controller;

import com.neusoft.weekreport.component.bizService.WeekBizService;
import com.neusoft.weekreport.component.req.*;
import com.neusoft.weekreport.component.resp.GetWeekDetailInfoResp;
import com.neusoft.weekreport.component.resp.GetWeekSummaryResp;
import com.neusoft.weekreport.component.resp.ResponseBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@EnableTransactionManagement
@RequestMapping("/week")
public class WeekController {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    WeekBizService weekBizService;

    //添加项目任务周报
    @RequestMapping(value="/addWeekDetail",method = RequestMethod.POST)
    public ResponseBean addWeekDetaiList(@RequestBody GetAddProjectWorkListReq req, HttpServletRequest request){
        ResponseBean responseBean = new ResponseBean<>();
        try{
            weekBizService.addProjectWeekDetaiList(req);
            responseBean = new ResponseBean(HttpStatus.OK.value(),"添加项目任务周报失败",responseBean);
        }catch (Exception e){
            responseBean.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
            responseBean.setMsg(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
            logger.error(e.toString());
        }
        return responseBean;
    }

    //添加产品任务周报明细
    @RequestMapping(value="/addProductWeekDetail",method = RequestMethod.POST)
    public ResponseBean addWeekDetaiList(@RequestBody GetAddProductWorkListReq req, HttpServletRequest request){
        ResponseBean responseBean = new ResponseBean<>();
        try{
            weekBizService.addProductWeekDetaiList(req);
            responseBean = new ResponseBean(HttpStatus.OK.value(),"添加研发任务周报失败",responseBean);
        }catch (Exception e){
            responseBean.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
            responseBean.setMsg(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
            logger.error(e.toString());
        }
        return responseBean;
    }
    //查询项目和研发任务周报
    @RequestMapping(value = "/weekDetailManage",method = RequestMethod.POST)
    public ResponseBean<GetWeekDetailInfoResp> getWeekDetailInfoList(@RequestBody GetWeekDetailListReq req,HttpServletRequest request){
        ResponseBean<GetWeekDetailInfoResp> responseBean = new ResponseBean<>();
        try{
            GetWeekDetailInfoResp resp = weekBizService.getWeekDetailInfoList(req);
            responseBean = new ResponseBean(HttpStatus.OK.value(),"查询研发任务周报成功",resp);
        }catch(Exception e){
            responseBean.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
            responseBean.setMsg(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
            logger.error(e.toString());
        }
        return responseBean;

    }
    //删除产品研发任务周报
    @RequestMapping(value = "/weekDetailManage",method = RequestMethod.DELETE)
    public ResponseBean deleteWeekInfo(@RequestBody GetDeleteWeekReq req,HttpServletRequest request){
        ResponseBean responseBean = new ResponseBean();
        try{
            weekBizService.deleteWeekInfo(req);
            responseBean = new ResponseBean(HttpStatus.OK.value(),"查询研发任务周报成功",responseBean);
        }catch(Exception e){
            responseBean.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
            responseBean.setMsg(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
            logger.error(e.toString());
        }
        return responseBean;
    }

    //查询本周研发任务和项目支持概述
    @RequestMapping(value = "/weekSummaryQuery",method = RequestMethod.POST)
    public ResponseBean<GetWeekSummaryResp> getWeekSummaryInfoList(@RequestBody  GetWeekSummaryReq req) throws Exception{
        ResponseBean<GetWeekSummaryResp> responseBean = new ResponseBean<>();
        try{
            GetWeekSummaryResp resp = weekBizService.getWeekSummaryInfoList(req);
            responseBean = new ResponseBean(HttpStatus.OK.value(),"查询本周周报概述成功",resp);
        }catch(Exception e){
            responseBean.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
            responseBean.setMsg(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
            logger.error(e.toString());
        }
        return responseBean;
    }

    //提交周报概述
    @RequestMapping(value = "/submitWeekSummary",method = RequestMethod.POST)
    public ResponseBean submitWeekSummaryInfo(@RequestBody GetAddWeekSummaryReq req) throws Exception{
        ResponseBean responseBean = new ResponseBean();
        try{
            weekBizService.submitWeekSummaryInfo(req);
            responseBean = new ResponseBean(HttpStatus.OK.value(),"提交本周周报概述成功",responseBean);

        }catch(Exception e){
            responseBean.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
            responseBean.setMsg(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
            logger.error(e.toString());
        }
        return responseBean;
    }



}
